package cn.patient.pp.module.patients.controller.admin;

import cn.patient.pp.framework.apilog.core.annotation.ApiAccessLog;
import cn.patient.pp.framework.common.pojo.CommonResult;
import cn.patient.pp.framework.common.pojo.PageParam;
import cn.patient.pp.framework.common.pojo.PageResult;
import cn.patient.pp.framework.datapermission.core.annotation.DataPermission;
import cn.patient.pp.framework.security.core.LoginUser;
import cn.patient.pp.framework.security.core.util.SecurityFrameworkUtils;
import cn.patient.pp.module.patients.controller.admin.vo.*;
import cn.patient.pp.module.patients.controller.admin.vo.binscreen.BigScreenCheckPatient;
import cn.patient.pp.module.patients.controller.admin.vo.binscreen.SuspectedMentalDisorderVo;
import cn.patient.pp.module.patients.service.BigScreenService;
import cn.patient.pp.module.system.dal.dataobject.user.AdminUserDO;
import cn.patient.pp.module.system.service.dept.DeptService;
import cn.patient.pp.module.system.service.user.AdminUserService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.apache.commons.lang3.StringUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

import static cn.patient.pp.framework.apilog.core.enums.OperateTypeEnum.GET;
import static cn.patient.pp.framework.common.pojo.CommonResult.success;

@Tag(name = "管理后台 - 大屏")
@RestController
@RequestMapping("/bigScreen")
@Validated
public class BigScreenController {

    @Resource
    private BigScreenService bigScreenService;

    @PostMapping("/riskProportion")
    @Operation(summary = "大屏患者危险性占比")
    @ApiAccessLog(operateType = GET)
    @DataPermission(enable = false)
    //@PreAuthorize("@ss.hasPermission('bigScreen:riskProportion')")
    public CommonResult<RiskProportionRespVO> getRiskProportion(@RequestBody BigScreenReqVO reqVO) {
        LoginUser loginUser = SecurityFrameworkUtils.getLoginUser();
        reqVO.setUserId(loginUser.getId());
        return success(bigScreenService.getRiskProportion(reqVO));
    }

    @PostMapping("/riskTypeProportion")
    @Operation(summary = "大屏患者危险性类型占比")
    @ApiAccessLog(operateType = GET)
    @DataPermission(enable = false)
    //@PreAuthorize("@ss.hasPermission('bigScreen:riskTypeProportion')")
    public CommonResult<List<RiskTypeProportionRespVO>> getRiskTypeProportion(@RequestBody BigScreenReqVO reqVO) {
        LoginUser loginUser = SecurityFrameworkUtils.getLoginUser();
        reqVO.setUserId(loginUser.getId());
        return success(bigScreenService.getRiskTypeProportion(reqVO));
    }

    @PostMapping("/increaseProportion")
    @Operation(summary = "患者增加数量")
    @ApiAccessLog(operateType = GET)
    @DataPermission(enable = false)
    //@PreAuthorize("@ss.hasPermission('bigScreen:increaseProportion')")
    public CommonResult<List<IncreaseProportionRespVO>> increaseProportion(@RequestBody BigScreenReqVO reqVO) {
        LoginUser loginUser = SecurityFrameworkUtils.getLoginUser();
        reqVO.setUserId(loginUser.getId());
        return success(bigScreenService.getIncreaseProportion(reqVO));
    }

    @PostMapping("/highRiskPatients")
    @Operation(summary = "高危患者新增数量")
    @ApiAccessLog(operateType = GET)
    @DataPermission(enable = false)
    //@PreAuthorize("@ss.hasPermission('bigScreen:highRiskPatients')")
    public CommonResult<List<HighRiskPatientsRespVO>> highRiskPatients(@RequestBody BigScreenReqVO reqVO) {
        LoginUser loginUser = SecurityFrameworkUtils.getLoginUser();
        reqVO.setUserId(loginUser.getId());
        return success(bigScreenService.getHighRiskPatients(reqVO));
    }

    @PostMapping("/followUpTrends")
    @Operation(summary = "随访趋势")
    @ApiAccessLog(operateType = GET)
    @DataPermission(enable = false)
    //@PreAuthorize("@ss.hasPermission('bigScreen:followUpTrends')")
    public CommonResult<List<FollowUpTrendsRespVO>> followUpTrends(@RequestBody BigScreenReqVO reqVO) {
        LoginUser loginUser = SecurityFrameworkUtils.getLoginUser();
        reqVO.setUserId(loginUser.getId());
        return success(bigScreenService.getFollowUpTrends(reqVO));
    }

    @PostMapping("/alarm")
    @Operation(summary = "报警信息")
    @ApiAccessLog(operateType = GET)
    @DataPermission(enable = false)
    @PreAuthorize("@ss.hasPermission('patients:alarmInfo:query')")
    public CommonResult<PageResult<AlarmRespVO>> alarm(@RequestBody @Valid AlarmReqVO reqVO) {
        return success(bigScreenService.getAlarm(reqVO));
    }

    @PostMapping("increaseAlarm")
    @Operation(summary = "危险程度变化报警信息")
    @ApiAccessLog(operateType = GET)
    @DataPermission(enable = false)
    public CommonResult<PageResult<increaseAlarmVo>> increaseAlarm(@RequestBody @Valid NewCheckAlarmReqVO reqVO) {
        return success(bigScreenService.getIncreaseAlarm(reqVO));
    }


    @PostMapping("/newCheckAlarm")
    @Operation(summary = "新筛查鉴定报警信息")
    @ApiAccessLog(operateType = GET)
    @DataPermission(enable = false)
    //@PreAuthorize("@ss.hasPermission('bigScreen:newCheckAlarm')")
    public CommonResult<PageResult<NewCheckAlarmRespVO>> newCheckAlarm(@RequestBody @Valid NewCheckAlarmReqVO reqVO) {
        return success(bigScreenService.getNewCheckAlarm(reqVO));
    }

    @PostMapping("/alarmMessage")
    @Operation(summary = "发送短信提醒")
    @ApiAccessLog(operateType = GET)
    @DataPermission(enable = false)
    //@PreAuthorize("@ss.hasPermission('bigScreen:alarmMessage')")
    public CommonResult<String> alarmMessage(@RequestBody @Valid List<AlarmMessageReqVO> reqVOS) {
        return success(bigScreenService.alarmMessage(reqVOS));
    }

    @PostMapping("/cureRate")
    @Operation(summary = "治愈率")
    @ApiAccessLog(operateType = GET)
    @DataPermission(enable = false)
    //@PreAuthorize("@ss.hasPermission('bigScreen:cureRate')")
    public CommonResult<PageResult<CureRateRespVO>> cureRate(@RequestBody @Valid PageParam pageParam) {
        return success(bigScreenService.getCureRate(pageParam));
    }
    @PostMapping("/checkPatientsCount")
    @Operation(summary = "新筛查鉴定统计")
    @ApiAccessLog(operateType = GET)
    @DataPermission(enable = false)
    //@PreAuthorize("@ss.hasPermission('bigScreen:cureRate')")
    public CommonResult<BigScreenCheckPatient> newPatientsCount (@RequestBody @Valid BigScreenReqVO pageParam) {
        return success(bigScreenService.newPatientsCount(pageParam));
    }

    @PostMapping("/patientFaceVisitRate")
    @Operation(summary = "患者面访率")
    @ApiAccessLog(operateType = GET)
    @DataPermission(enable = false)
    //@PreAuthorize("@ss.hasPermission('bigScreen:patientFaceVisitRate')")
    public CommonResult<Double> patientFaceVisitRate(@RequestBody @Valid BigScreenReqVO pageParam) {
        return success(bigScreenService.patientFaceVisitRate(pageParam));
    }

    @PostMapping("/lostContactCount")
    @Operation(summary = "失访人员数量")
    @DataPermission(enable = false)
    //@PreAuthorize("@ss.hasPermission('bigScreen:lostContactCount')")
    public CommonResult<List<LostContactCountRespVO>> lostContactCount(@RequestBody @Valid BigScreenReqVO pageParam) {
        return success(bigScreenService.lostContactCount(pageParam));
    }
    @PostMapping("/suspectedMentalDisorder")
    @Operation(summary = "疑似精神病障碍患者排查情况")
    @ApiAccessLog(operateType = GET)
    @DataPermission(enable = false)
    //@PreAuthorize("@ss.hasPermission('bigScreen:lostContactCount')")
    public CommonResult<SuspectedMentalDisorderVo> suspectedMentalDisorder(@RequestBody @Valid BigScreenReqVO pageParam) {
        return success(bigScreenService.suspectedMentalDisorder(pageParam));
    }
}
